package com.shop2cn.iapi.couponmanage.testcase.old;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.couponmanage.parameter.CreateBean;
import com.shop2cn.iapi.couponmanage.parameter.CreateCouponBean;
import com.shop2cn.iapi.couponmanage.parameter.GetConversionCodesByPagingBean;
import com.shop2cn.iapi.couponmanage.service.CreateCouponCall;
import com.shop2cn.iapi.couponmanage.service.GetConversionCodesByPagingCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.database.model.couponconversion;
import com.ymttest.database.model.couponconversioncode;
import com.ymttest.database.sqlwapper.couponconversionWapper;
import com.ymttest.database.sqlwapper.couponconversioncodeWapper;
//import com.ymttest.database.model.couponconversion;
//import com.ymttest.database.model.couponconversioncode;
//import com.ymttest.database.sqlwapper.couponconversionWapper;
//import com.ymttest.database.sqlwapper.couponconversioncodeWapper;
/**
*获取兑换码列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetConversionCodesByPaging{
	private static GetConversionCodesByPagingBean getconversioncodesbypagingBean;
	private static GetConversionCodesByPagingCall getconversioncodesbypagingCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取兑换码列表");
	}

	@Before
	public void caseUp() {
		getconversioncodesbypagingBean=new GetConversionCodesByPagingBean();
		getconversioncodesbypagingCall=new GetConversionCodesByPagingCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getconversioncodesbypagingCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetConversionCodesByPaging_001() {
		Logger.start(true,"获取兑换码列表");
		try { 
		
			couponconversion bill = new couponconversionWapper().getTop1();
			getconversioncodesbypagingBean.setConversionBillId(bill.getConversionId());
			getconversioncodesbypagingBean.setPageIndex(1);
			getconversioncodesbypagingBean.setPageSize(20);
			
			getconversioncodesbypagingCall.setData(getconversioncodesbypagingBean);
			getconversioncodesbypagingCall.callService();			
			
			Logger.verifyEquals("0", getconversioncodesbypagingCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getconversioncodesbypagingCall.getMessage(), "验证返回Message");

			List<String> conversionCodes = getconversioncodesbypagingCall.getConversionCodes().getConversionCodes();
			
			List<couponconversioncode> codes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			for (int i=0;i<codes.size();i++) {

				Logger.verifyEquals(codes.get(i).getConversionCode(),conversionCodes.get(i), "验证返回conversionCodes");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetConversionCodesByPaging_009() {
		Logger.start(true,"获取兑换码列表-总数小于当页最大条数");
		try { 
		
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setAcquireCouponMethod(2);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			List<String> batchCodes= new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());
			CreateBean CreateBean=couponCallService.setDefaultRandomCreateBean(batchCodes);
			couponCallService.create(CreateBean);
		
			
			couponconversion bill = new couponconversionWapper().getTop1();
			getconversioncodesbypagingBean.setConversionBillId(bill.getConversionId());
			getconversioncodesbypagingBean.setPageIndex(1);
			getconversioncodesbypagingBean.setPageSize(10);
			
			getconversioncodesbypagingCall.setData(getconversioncodesbypagingBean);
			getconversioncodesbypagingCall.callService();			
			
			Logger.verifyEquals("0", getconversioncodesbypagingCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getconversioncodesbypagingCall.getMessage(), "验证返回Message");

			List<String> conversionCodes = getconversioncodesbypagingCall.getConversionCodes().getConversionCodes();
			List<couponconversioncode> codes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			for (int i=0;i<codes.size();i++) {
				Logger.verifyEquals(codes.get(0).getConversionCode(),conversionCodes.get(0), "验证返回conversionCodes");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetConversionCodesByPaging_010() {
		Logger.start(true,"获取兑换码列表-总数大于当页最大条数");
		try { 
		
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setAcquireCouponMethod(2);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			List<String> batchCodes= new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());
			CreateBean CreateBean=couponCallService.setDefaultRandomCreateBean(batchCodes);
			couponCallService.create(CreateBean);
		
			Thread.sleep(10000);
			couponconversion bill = new couponconversionWapper().getTop1();
			getconversioncodesbypagingBean.setConversionBillId(bill.getConversionId());
			getconversioncodesbypagingBean.setPageIndex(1);
			getconversioncodesbypagingBean.setPageSize(1);
			
			getconversioncodesbypagingCall.setData(getconversioncodesbypagingBean);
			getconversioncodesbypagingCall.callService();			
			
			Logger.verifyEquals("0", getconversioncodesbypagingCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getconversioncodesbypagingCall.getMessage(), "验证返回Message");

			List<String> conversionCodes = getconversioncodesbypagingCall.getConversionCodes().getConversionCodes();
			
			List<couponconversioncode> codes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			//for (int i=0;i<codes.size();i++) {

				Logger.verifyEquals(codes.get(0).getConversionCode(),conversionCodes.get(0), "验证返回conversionCodes");
			//}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetConversionCodesByPaging_002() {
		Logger.start(true,"获取兑换码列表-ConversionBillId空");
		try {
		
			getconversioncodesbypagingBean.setPageIndex(1);
			getconversioncodesbypagingBean.setPageSize(20);
			
			getconversioncodesbypagingCall.setData(getconversioncodesbypagingBean);
			getconversioncodesbypagingCall.callService();			
			
			Logger.verifyEquals("0", getconversioncodesbypagingCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getconversioncodesbypagingCall.getMessage(), "验证返回Message");

			List<String> conversionCodes = getconversioncodesbypagingCall.getConversionCodes().getConversionCodes();
			Logger.verifyEquals(0, conversionCodes.size(), "验证无返回conversionCodes");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetConversionCodesByPaging_003() {
		Logger.start(true,"获取兑换码列表-ConversionBillId空不存在");
		try {
		
			getconversioncodesbypagingBean.setConversionBillId(99999);
			getconversioncodesbypagingBean.setPageIndex(1);
			getconversioncodesbypagingBean.setPageSize(20);
			
			getconversioncodesbypagingCall.setData(getconversioncodesbypagingBean);
			getconversioncodesbypagingCall.callService();			
			
			Logger.verifyEquals("0", getconversioncodesbypagingCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getconversioncodesbypagingCall.getMessage(), "验证返回Message");

			List<String> conversionCodes = getconversioncodesbypagingCall.getConversionCodes().getConversionCodes();
			Logger.verifyEquals(0, conversionCodes.size(), "验证无返回conversionCodes");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetConversionCodesByPaging_004() {
		Logger.start(true,"获取兑换码列表-pageIndex空");
		try {
		
			getconversioncodesbypagingBean.setConversionBillId(99999);
			getconversioncodesbypagingBean.setPageSize(20);
			
			getconversioncodesbypagingCall.setData(getconversioncodesbypagingBean);
			getconversioncodesbypagingCall.callService();			
			
//			Logger.verifyEquals("2", getconversioncodesbypagingCall.getCode(), "验证返回code");
			Logger.verifyIsContains("pageIndex:pageIndex must greater than or equal to 1", getconversioncodesbypagingCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetConversionCodesByPaging_005() {
		Logger.start(true,"获取兑换码列表-pageSize空");
		try {
		
			getconversioncodesbypagingBean.setConversionBillId(99999);
			getconversioncodesbypagingBean.setPageSize(20);
			
			getconversioncodesbypagingCall.setData(getconversioncodesbypagingBean);
			getconversioncodesbypagingCall.callService();			
			
//			Logger.verifyEquals("2", getconversioncodesbypagingCall.getCode(), "验证返回code");
			Logger.verifyIsContains("pageIndex:pageIndex must greater than or equal to 1", getconversioncodesbypagingCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetConversionCodesByPaging_006() {
		Logger.start(true,"获取兑换码列表-pageindex大于总页数");
		try {
		
			couponconversion bill = new couponconversionWapper().getTop1();
			
			getconversioncodesbypagingBean.setConversionBillId(bill.getConversionId());
			getconversioncodesbypagingBean.setPageIndex(107);
			getconversioncodesbypagingBean.setPageSize(20);
			
			getconversioncodesbypagingCall.setData(getconversioncodesbypagingBean);
			getconversioncodesbypagingCall.callService();			
			
			Logger.verifyEquals("0", getconversioncodesbypagingCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getconversioncodesbypagingCall.getMessage(), "验证返回Message");

			List<String> conversionCodes = getconversioncodesbypagingCall.getConversionCodes().getConversionCodes();
			Logger.verifyEquals(0, conversionCodes.size(), "验证无返回conversionCodes");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetConversionCodesByPaging_008() {
		Logger.start(true,"获取兑换码列表-pagesize=0");
		try {
		
			couponconversion bill = new couponconversionWapper().getTop1();
			
			getconversioncodesbypagingBean.setConversionBillId(bill.getConversionId());
			getconversioncodesbypagingBean.setPageIndex(1);
			getconversioncodesbypagingBean.setPageSize(0);
			
			getconversioncodesbypagingCall.setData(getconversioncodesbypagingBean);
			getconversioncodesbypagingCall.callService();			
			
//			Logger.verifyEquals("2", getconversioncodesbypagingCall.getCode(), "验证返回code");
			Logger.verifyIsContains("pageSize:每页大小为1-1000", getconversioncodesbypagingCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}